﻿var guideString;
var address;
var startPoint;
var endPoint;
var service;
var nearBy;
var myLocation;

var scrHeight;
var scrWidth;
var maxWidth;
var maxHeight;

//function setCookie(cookieName, cookieValue, numDays)
//{
//    var time = numDays*24*60*60*1000;
//    var expDate = new Date();
//    expDate.setTime(expDate.getTime() + time);
//    var cookieExpires = expDate.toGMTString();
//    alert(expDate);
//    document.cookie = cookieName + "=" + cookieValue + "; expires=" + cookieExpires;
//    alert("2");
//}

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(cookieName)
{
    var results = document.cookie.match ( '(^|;) ?' + cookieName + '=([^;]*)(;|$)' );

    if(results != null)
        return "existed";
    else
        return null;
}

function ShowHideDivAddress()
{
    if(document.getElementById("divAddress").style.display == "none"){
        document.getElementById("divAddress").style.display = "block";
    }              
    else{
        document.getElementById("divAddress").style.display = "none";
    }
        
    document.getElementById("divDirection").style.display = "none";
    document.getElementById("divService").style.display = "none";
    document.getElementById("divLanguage").style.display = "none";
    
    return false;
}

//-----------------------------------------------------------------------
function GetScreenSize()
{
    scrHeight = document.body.clientHeight;
    scrWidth = document.body.clientWidth;
    if(scrHeight > maxHeight)
        scrHeight = maxHeight;
    if(scrWidth > maxWidth)
        scrWidth = maxWidth;
    
    setCookie("mobimap_scrHeight", scrHeight, 15);
}

function ShowHideDivDirection()
{       
    if(document.getElementById("divDirection").style.display == "none"){
        document.getElementById("divDirection").style.display = "block";
    }              
    else{
        document.getElementById("divDirection").style.display = "none";
    }
        
    document.getElementById("divAddress").style.display = "none";
    document.getElementById("divService").style.display = "none";
    document.getElementById("divLanguage").style.display = "none";
    
    return false;
}


function ShowHideDivService()
{
    if(document.getElementById("divService").style.display == "none"){
        document.getElementById("divService").style.display = "block";
    }              
    else{
        document.getElementById("divService").style.display = "none";
    }
        
    document.getElementById("divAddress").style.display = "none";
    document.getElementById("divDirection").style.display = "none";
    document.getElementById("divLanguage").style.display = "none";
    
    return false;
}

function ShowHideDivLanguage()
{
    if(document.getElementById("divLanguage").style.display == "none"){
        document.getElementById("divLanguage").style.display = "block";
    }              
    else{
        document.getElementById("divLanguage").style.display = "none";
    }
        
    document.getElementById("divAddress").style.display = "none";
    document.getElementById("divDirection").style.display = "none";
    document.getElementById("divService").style.display = "none";
    
    return false;
}


function ClearText(txtInput, me)
{ 
    getValue(txtInput);
    if(me.value == guideString)
        me.value = "";
    else
        me.select();
        
    me.style.color = "Black";
    
}

function FillText(me)
{
    var node = document.getElementById(me.id);
    if(node.value == "")
    {
        node.value = guideString;
        node.style.color = "#907777";
    }
}
function getValue(txtInput)
{
    if(txtInput == "txtAddress")
        guideString = address;
    else if(txtInput == "txtStartPoint")
        guideString = startPoint;
    else if(txtInput == "txtEndPoint")
        guideString = endPoint;
    else if(txtInput == "txtService")
        guideString = service;
    else if(txtInput == "txtNearBy")
        guideString = nearBy;        
}

function ChangeLanguage(language)
{    
    setCookie("language", language, 15);
    document.location.href = document.location;
}

function InvertText(id1, id2)
{    
    var node1 = document.getElementById(id1);
    var node2 = document.getElementById(id2);
    
    if(node1.value != startPoint && node2.value != endPoint)
    {
        var temp = node1.value;
        node1.value = node2.value;
        node2.value = temp;
        return;
    }
    
    if(node1.value != startPoint && node2.value == endPoint)
    {   
        node2.value = node1.value;     
        node1.value = startPoint;
        return;
    }
    
    if(node1.value == startPoint && node2.value != endPoint)
    {   
        node1.value = node2.value;     
        node2.value = endPoint;
        return;
    }
}
/*Di chuyen ban do----------------------------------------------------------------*/
function hideFlag()
{
    document.getElementById("imgFlag").style.display = "none";
    document.getElementById("imgEnd").style.display = "none";
    document.getElementById("divInfo").style.display = "none";
}

function MoveMap(orientation)
{    
    hideFlag();
    var url = "move=" + orientation;            
    LoadMap(url);
}

function ChangeType(selectedIndex)
{
    var url = "type=" + selectedIndex;    
    LoadMap(url);
}

function Zoom(delta)
{
    hideFlag();
    var url = "zoom=" + delta; 
    LoadMap(url);
}

function GetDefaultMap()
{
    var url = "screenWidth=" + document.body.offsetWidth;
    url += "&screenHeight=" + document.body.offsetHeight;
    LoadMap(url);
}

function GetPlaceInfo()
{
    xmlHttp = getXmlHttpObject();
    if(xmlHttp == null)
    {
	    alert("Your browser does not support XML HTTP Request!!!");
	    return;
    }
	
    var url = "GetPlaceInfo.aspx" + "?t=" + new Date().getTime();
    
    xmlHttp.onreadystatechange = GetDataFromServer;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    //GetDataFromServer();
}

function getXmlHttpObject()
{
    if(window.XMLHttpRequest)
    {
	    return new XMLHttpRequest();
    }
    if(window.ActiveXObject)
    {
	    return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}    



//------------------------- Get elememt properties
function getElementLeft(elem) 
{	    
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function getElementTop(elem) 
{	    
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
	}
	return yPos;
}
